home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1999
/
MacHack 1999.toast
/
The Hacks
/
CarbonizedMenus
/
source
/
jGNE.c
< prev
next >
Wrap
Text File
|
1999-06-25
|
3KB
|
113 lines
/****************************************************************************************
jGNE.c
Copyright © 1999 Red Shed Software. All rights reserved.
by Jonathan 'Wolf' Rentzsch (jon@redshed.net)
Commenter Date Comment
--------- ----------------- -----------------------------------------------------
wolf Fri, Jun 18, 1999 Created.
************************************************************************************/
#include "jGNE.h"
#include "OSUtils.h"
#pragma options align=mac68k
typedef struct {
UInt16 jumpInstruction; // always 0x4EF9 (jmp)
GetNextEventFilterUPP jumpAddress;
} jGNEJumpIsland;
#pragma options align=reset
jGNEJumpIsland *gJumpIsland = nil;
GetNextEventFilterUPP gNextFilter = nil;
#if powerc
#define FlushCache( PTR, SIZE ) noErr;MakeDataExecutable((PTR),(SIZE))
#else
#define FlushCache( PTR, SIZE ) FlushCodeCacheRange((PTR),(SIZE))
#endif
/****************************************************************************************
Commenter Date Comment
--------- ----------------- -----------------------------------------------------
wolf Tue, Jun 22, 1999 Created.
************************************************************************************/
OSErr
InstalljGNE(
GetNextEventFilterUPP proc )
{
OSErr err = noErr;
if( gJumpIsland )
err = paramErr;
if( !err ) {
gJumpIsland = (jGNEJumpIsland*) NewPtrSys( sizeof( jGNEJumpIsland ) );
err = MemError();
if( !gJumpIsland && !err )
err = memFullErr;
}
if( !err ) {
gJumpIsland->jumpInstruction = 0x4EF9; // JMP
gJumpIsland->jumpAddress = proc;
err = FlushCache( gJumpIsland, sizeof( jGNEJumpIsland ) );
}
if( !err ) {
gNextFilter = LMGetGNEFilter();
LMSetGNEFilter( (GetNextEventFilterUPP) gJumpIsland );
}
if( err && gJumpIsland ) {
DisposePtr( (Ptr) gJumpIsland );
gJumpIsland = nil;
}
return( err );
}
/****************************************************************************************
Commenter Date Comment
--------- ----------------- -----------------------------------------------------
wolf Thu, Jun 24, 1999 Created.
************************************************************************************/
GetNextEventFilterUPP
GetNextjGNE()
{
return( gNextFilter );
}
/****************************************************************************************
Commenter Date Comment
--------- ----------------- -----------------------------------------------------
wolf Tue, Jun 22, 1999 Created.
************************************************************************************/
OSErr
RemovejGNE()
{
OSErr err = noErr;
if( !gJumpIsland || !gNextFilter )
err = paramErr;
if( !err ) {
gJumpIsland->jumpAddress = gNextFilter;
err = FlushCache( gJumpIsland, sizeof( jGNEJumpIsland ) );
}
if( !err ) {
gJumpIsland = nil;
gNextFilter = nil;
}
return( err );
}